﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IRDev.Library.ExpandedException.Common
{
    /// <summary>
    /// ExpandedException for better standard error handling. 
    /// Serializable so all exceptions can be sent the same way. 
    /// Element grouping 
    /// From IRDev Library Project by Mark Rowe markwrowe@hotmail.com  http://everythingworkflow.spaces.live.com  ,  Daniel Turnell daniel.turnell@gmail.com
    /// This Project http://autodeploy.codeplex.com
    /// </summary>  
    [Serializable()]
    public class ExpandedException : Exception
    {
        //Calling ClassName
        public Exception ex { get; set; }
        public string ClassName { get; set; }
        //Calling MethodName
        public string MethodName { get; set; }
        //The input paramaters (in ToString() format)
        public string ParametersInput {get; set;}
        //More flexible than GUID or Int since both can be input as a string
        public string MessageID {get; set;}
        //Exception Reported
        public string TimeOfException { get; set; }
        //Has the Exception Been Reported
        public bool Reported { get; set; }
        //Constructor

        public ExpandedException()
        {
            ClassName = string.Empty;
            MethodName = string.Empty;
            ParametersInput = string.Empty;
            MessageID = string.Empty;
            TimeOfException = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
            Reported = false;
        }
        public ExpandedException(Exception ex)
        {
            this.ex = ex;
            ClassName = string.Empty;
            MethodName = string.Empty;
            ParametersInput = string.Empty;
            MessageID = string.Empty;
            TimeOfException = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
            Reported = false;
        }
        /// <summary>
        /// Better ToString :D
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Expanded Error\n");
            sb.Append("Class" + ClassName + "\n");
            sb.Append("Method:" + MethodName + "\n");
            sb.Append("Parameters:" + ParametersInput + "\n");
            sb.Append("MessageID:" + MessageID + "\n");
            sb.Append("Reported:" + Reported + "\n");
            sb.Append("Time Of Exception:" + TimeOfException + "\n");
            sb.Append("Message:" + ex.Message + "\n");
            if (ex.InnerException != null)
            {
                sb.Append("InnerException" + ex.InnerException.ToString() + "\n");
            }
            return sb.ToString();
        }
    }
}
